package tech.senri.iot.socket

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.CommandLineRunner
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.Bean
import springfox.documentation.swagger2.annotations.EnableSwagger2
import tech.senri.iot.socket.service.socket.TCPServer
import springfox.documentation.builders.ApiInfoBuilder
import springfox.documentation.service.ApiInfo
import springfox.documentation.builders.PathSelectors
import springfox.documentation.builders.RequestHandlerSelectors
import springfox.documentation.spi.DocumentationType
import springfox.documentation.spring.web.plugins.Docket



@SpringBootApplication
@EnableSwagger2
class SocketServiceApplication : CommandLineRunner
{
    @Bean
    fun createRestApi(): Docket
    {
        return Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .paths(PathSelectors.any())
                .build()
    }

    private fun apiInfo(): ApiInfo
    {
        return ApiInfoBuilder()
                .title("swagger-bootstrap-ui RESTful APIs")
                .description("swagger-bootstrap-ui")
                .termsOfServiceUrl("http://localhost:8999/")
                .version("1.0")
                .build()
    }

    @Autowired
    private lateinit var tcpServer: TCPServer

    override fun run(vararg args: String?)
    {
        tcpServer.start()
    }
}

fun main(args: Array<String>)
{
    runApplication<SocketServiceApplication>(*args)
}
